﻿
namespace Service
{
	using System.Linq;
	using Data.Repository;
	using System.Collections.Generic;

	public class NewsService : INewsService
	{
		private INewsRepository _newsRepository;

		#region INewsService Members

		public int CreateNews(Data.Entity.News theNewNews)
		{
			if (theNewNews == null)
			{
				return 0;
			}

			if (_newsRepository == null)
			{
				_newsRepository = new NewsRepository();
			}

			return _newsRepository.CreateNews(theNewNews);
		}

		public IList<Data.Entity.News> GetNewsByLanguage(int languageID)
		{
			if (languageID <= 0)
			{
				return null;
			}

			if (_newsRepository == null)
			{
				_newsRepository = new NewsRepository();
			}

			return _newsRepository.GetNewsByLanguage(languageID);
		}

		public int DeleteNews(int newsID)
		{
			if (newsID <= 0)
			{
				return 0;
			}

			if (_newsRepository == null)
			{
				_newsRepository = new NewsRepository();
			}

			return _newsRepository.DeleteNews(newsID);
		}

		public IList<Data.Entity.News> GetAllNewsByLanguage(int languageID)
		{
			if (languageID <= 0)
			{
				return null;
			}

			if (_newsRepository == null)
			{
				_newsRepository = new NewsRepository();
			}

			return _newsRepository.GetAllNewsByLanguage(languageID);
		}

		public Data.Entity.News GetTheNews(int id)
		{
			if (id <= 0)
			{
				return null;
			}

			if (_newsRepository == null)
			{
				_newsRepository = new NewsRepository();
			}

			return _newsRepository.GetTheNews(id);
		}

		public int UpdateNews(Data.Entity.News theNews)
		{
			if (theNews == null || theNews.NewsID <= 0)
			{
				return 0;
			}

			if (_newsRepository == null)
			{
				_newsRepository = new NewsRepository();
			}

			return _newsRepository.UpdateNews(theNews);
		}

		#endregion
	}
}
